/*
 * Copyright 2008 Jens Meiss
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mtt.appinfo;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;

import mtt.menu.events.ShowMainMenuEvent;
import mtt.rms.events.recordstores.marks.events.GetNumMarkRecordsEvent;
import mtt.rms.events.recordstores.marks.events.SetNumMarkRecordsEvent;
import mtt.rms.recordstores.calendar.events.GetNumCalendarRecordsEvent;
import mtt.rms.recordstores.calendar.events.SetNumCalendarRecordsEvent;

import hmvc.j2me.events.IEvent;
import hmvc.j2me.events.TerminateEvent;
import hmvc.j2me.view.AView;

/**
 *
 *
 * @author jens.meiss
 */
public class ApplicationInfoView extends AView {
	
	private Form form = new Form("MTT - Informationen");
	
	private Command commandBack = new Command("zurück", Command.BACK, 0);

	public void handleEvent(IEvent event) {
		
		if (event instanceof SetNumCalendarRecordsEvent) {
			SetNumCalendarRecordsEvent numCalendarRecordsEvent = (SetNumCalendarRecordsEvent) event;
			form.append("Gespeicherte Termine: " + numCalendarRecordsEvent.getNumCalendarRecords());
		} else if (event instanceof SetNumMarkRecordsEvent) {
			SetNumMarkRecordsEvent numMarksRecordStoreEvent = (SetNumMarkRecordsEvent) event;
			form.append("Gespeicherte Noten/Punkte: " + numMarksRecordStoreEvent.getNumMarksRecords());
		}
		
	}

	public void terminate() {
	}

	public void init() {
		
		form.append("Author: Jens Meiß");
		form.append("Version: 0");
		form.append("Homepage: http://mobile-time-table.googlecode.com");
		form.append("Lizenz: Apache 2.0 (OpenSource)");
//		
		
		getController().fireEventUp(new GetNumCalendarRecordsEvent(getController().getComponent()));
		getController().fireEventUp(new GetNumMarkRecordsEvent(getController().getComponent()));
		
		form.addCommand(commandBack);
		
		setDisplayAble(form);
	}

	public void registerEvents() {
		getController().register(SetNumCalendarRecordsEvent.class, this);
		getController().register(SetNumMarkRecordsEvent.class, this);
	}

	public void commandAction(Command arg0, Displayable arg1) {
		
		if (arg0 == commandBack) {
			
			getController().fireEventUp(new ShowMainMenuEvent());
			getController().fireEventLocal(new TerminateEvent());
			
		}
		
	}

}
